package com.zrlh.file_trans_monitor.util;

import java.sql.Time;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {
    public static final String YYYYMMDDHHDDSS= "yyyyMMddHHmmss";

    //组合开始时间
    public static Date getST(Time time){
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String sDate = df.format(new Date());
        sDate = sDate.substring(0,11);
        sDate = sDate + time;
        try {
            return df.parse(sDate);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }
    public static String getDateString(Date date, String pattern) {
        return (new SimpleDateFormat(pattern)).format(date);
    }

    public static Date getCurrentTime() {
        return Calendar.getInstance().getTime();
    }

    public static String getShortDateStrNow() {
        return getDateString(getCurrentTime(), "yyyyMMdd");
    }
    public static String getShortDateYYYY_MM_DDStrNow() {
        return getDateString(getCurrentTime(), "yyyy-MM-dd");
    }
    public static String getShortDateYYYY_MM_DDStrYesterday(){
        Date today = new Date();
        Calendar c = Calendar.getInstance();
        c.setTime(today);
        c.add(Calendar.DAY_OF_MONTH, -1);
        Date yesterday = c.getTime();//这是昨天
        return getDateString(yesterday, "yyyy-MM-dd");
    }
}
